package org.example.fancystudy.interrupt;

import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

/**
 * @author chaigq
 * @version 1.0
 * @date 2022/11/10 11:39
 */
public class InterruptDemo1 {
    static AtomicBoolean atomicBoolean = new AtomicBoolean(false);

    public static void main(String[] args) {
        new Thread(() -> {
            while (true){
                if (atomicBoolean.get()){
                    System.out.println(Thread.currentThread().getName() + " atomicBoolean被修改停止");
                    break;
                }
                System.out.println(Thread.currentThread().getName() + " 运行");
            }
        }, "t1").start();

        try {
            TimeUnit.SECONDS.sleep(3);
        }catch (InterruptedException e){
            e.printStackTrace();
        }

        new Thread(() -> {
            atomicBoolean.set(true);
        },"t2").start();
    }
}
